<html>
<head><meta charset="utf-8"><title>Why does this work? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html">Why does this work?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244292349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244292349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244292349">(Jun 29 2021 at 14:42)</a>:</h4>
<p>I noticed that we don't eagerly unify a closure's argument types with the expected type in some cases, which leads to uninferred closure args, and unresolved inherent method calls. Basically we seem to be missing the code here: <a href="https://github.com/rust-lang/rust/blob/5d0fae5b66ea33e667c8e1f7cceaca0c3653597c/compiler/rustc_typeck/src/check/closure.rs#L158">https://github.com/rust-lang/rust/blob/5d0fae5b66ea33e667c8e1f7cceaca0c3653597c/compiler/rustc_typeck/src/check/closure.rs#L158</a></p>
<p>At least when the expected type is <code>&amp;dyn Fn(X)</code>, this seems to be correct, but for some reason the following seems to work fine, but I expected it to also fail:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">inherent</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">take_generic_closure</span><span class="p">(</span><span class="n">f</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="n">S</span><span class="p">))</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">take_generic_closure</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">inherent</span><span class="p">();</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w">                             </span><span class="c1">//^^^^^^^^^^^^ u8</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Where are we implementing this?</p>



<a name="244294439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294439">(Jun 29 2021 at 14:55)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/13cbe64a5908cfc36629687a302be9568a06afa4/crates/hir_ty/src/infer/expr.rs#L284-L289">https://github.com/rust-analyzer/rust-analyzer/blob/13cbe64a5908cfc36629687a302be9568a06afa4/crates/hir_ty/src/infer/expr.rs#L284-L289</a></p>



<a name="244294590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294590">(Jun 29 2021 at 14:55)</a>:</h4>
<p>hmm, where does <code>coerce</code> look at the where-clauses though?</p>



<a name="244294607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294607">(Jun 29 2021 at 14:56)</a>:</h4>
<p>the problem with <code>&amp;dyn Fn</code> might be an unsizing coercion problem?</p>



<a name="244294727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294727">(Jun 29 2021 at 14:56)</a>:</h4>
<p><code>coerce</code> calls <code>resolve_ty_shallow</code>, which calls <code>resolve_obligations_as_possible</code></p>



<a name="244294782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294782">(Jun 29 2021 at 14:56)</a>:</h4>
<p>at this point the where clause should already be registered as an obligation</p>



<a name="244294791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244294791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244294791">(Jun 29 2021 at 14:57)</a>:</h4>
<p>ah, okay</p>



<a name="244295086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295086">(Jun 29 2021 at 14:58)</a>:</h4>
<p>I think <code>dyn</code> doesn't work because <code>only_has_type</code> ignores <code>Expectation::RValueLikeUnsized</code></p>



<a name="244295102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295102">(Jun 29 2021 at 14:58)</a>:</h4>
<p>I think rustc doesn't do that</p>



<a name="244295220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295220">(Jun 29 2021 at 14:59)</a>:</h4>
<p>hmm the expectation won't be <code>RValueLikeUnsized</code> in your example though, I think?</p>



<a name="244295412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295412">(Jun 29 2021 at 15:00)</a>:</h4>
<p>ah well it might</p>



<a name="244295535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295535">(Jun 29 2021 at 15:00)</a>:</h4>
<p>it is</p>



<a name="244295562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295562">(Jun 29 2021 at 15:00)</a>:</h4>
<p>but that doesn't fix it</p>



<a name="244295781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295781">(Jun 29 2021 at 15:02)</a>:</h4>
<p>does it infer the type of <code>x</code> at all in the test?</p>



<a name="244295933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295933">(Jun 29 2021 at 15:02)</a>:</h4>
<p>I'm testing with</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">inherent</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">take_dyn_fn</span><span class="p">(</span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="n">S</span><span class="p">))</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">take_dyn_fn</span><span class="p">(</span><span class="o">&amp;|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">inherent</span><span class="p">();</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w">                     </span><span class="c1">//^^^^^^^^^^^^ u8</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="244295994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244295994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244295994">(Jun 29 2021 at 15:03)</a>:</h4>
<p>apparently it does, yes</p>



<a name="244296055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244296055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244296055">(Jun 29 2021 at 15:03)</a>:</h4>
<p>hrm</p>



<a name="244296266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244296266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244296266">(Jun 29 2021 at 15:04)</a>:</h4>
<p>yeah well just not doing <code>only_has_type</code> isn't going to help there, since the closure doesn't coerce to <code>dyn Fn</code> without <code>&amp;</code></p>



<a name="244296325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244296325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244296325">(Jun 29 2021 at 15:05)</a>:</h4>
<p>so yeah, this might need something like <code>deduce_expectations_from_expected_type</code> after all :(</p>



<a name="244352648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244352648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244352648">(Jun 29 2021 at 21:50)</a>:</h4>
<p>I came up with another interesting case that my PR doesn't fix:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">inherent</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">take_dyn_fn</span><span class="p">(</span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="k">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="n">S</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">take_dyn_fn</span><span class="p">(</span><span class="o">&amp;|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">x</span><span class="p">.</span><span class="n">inherent</span><span class="p">();</span><span class="w"></span>
<span class="w">      </span><span class="c1">//^^^^^^^^^^^^ u8</span>
<span class="w">        </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"></span>
<span class="w">      </span><span class="c1">//^^ &amp;u8</span>
<span class="w">    </span><span class="p">});</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Here the <code>DynTy</code> prints as <code>dyn for&lt;type&gt; [] + 'static</code>, which looks like we're just throwing away the higher-ranked bound. Is that a known bug?</p>



<a name="244354726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244354726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244354726">(Jun 29 2021 at 22:09)</a>:</h4>
<p>also I don't think I can just shift the <code>&amp;'a S</code> out of its binder here</p>



<a name="244355298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244355298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244355298">(Jun 29 2021 at 22:15)</a>:</h4>
<p>"let's see how rustc handles these binders correctly"</p>
<p><a href="https://github.com/rust-lang/rust/blob/6e0b554619a3bb7e75b3334e97f191af20ef5d76/compiler/rustc_typeck/src/check/closure.rs#L259">https://github.com/rust-lang/rust/blob/6e0b554619a3bb7e75b3334e97f191af20ef5d76/compiler/rustc_typeck/src/check/closure.rs#L259</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">arg_param_ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">projection</span><span class="p">.</span><span class="n">skip_binder</span><span class="p">().</span><span class="n">projection_ty</span><span class="p">.</span><span class="n">substs</span><span class="p">.</span><span class="n">type_at</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>:|</p>



<a name="244355410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244355410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244355410">(Jun 29 2021 at 22:16)</a>:</h4>
<p>ah, and then it <code>rebind</code>s everything in the <code>FnSig</code></p>



<a name="244356015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244356015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244356015">(Jun 29 2021 at 22:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Why.20does.20this.20work.3F/near/244352648">said</a>:</p>
<blockquote>
<p>I came up with another interesting case that my PR doesn't fix:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">inherent</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">take_dyn_fn</span><span class="p">(</span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="k">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="n">S</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">take_dyn_fn</span><span class="p">(</span><span class="o">&amp;|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">x</span><span class="p">.</span><span class="n">inherent</span><span class="p">();</span><span class="w"></span>
<span class="w">      </span><span class="c1">//^^^^^^^^^^^^ u8</span>
<span class="w">        </span><span class="o">&amp;</span><span class="mi">0</span><span class="w"></span>
<span class="w">      </span><span class="c1">//^^ &amp;u8</span>
<span class="w">    </span><span class="p">});</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Here the <code>DynTy</code> prints as <code>dyn for&lt;type&gt; [] + 'static</code>, which looks like we're just throwing away the higher-ranked bound. Is that a known bug?</p>
</blockquote>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/type_ref.rs#L303">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/type_ref.rs#L303</a> We are skipping them currently</p>



<a name="244356473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244356473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244356473">(Jun 29 2021 at 22:27)</a>:</h4>
<p>sadge</p>



<a name="244357058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244357058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244357058">(Jun 29 2021 at 22:34)</a>:</h4>
<p>I think I just didn't add it because the lifetime hir PR was big enough back then, could look into fixing that</p>



<a name="244358270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244358270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244358270">(Jun 29 2021 at 22:49)</a>:</h4>
<p>I do think we'll need this for accurate closure inference, but I can also look into it when I get the chance</p>



<a name="244358621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244358621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244358621">(Jun 29 2021 at 22:53)</a>:</h4>
<p>I wouldn't mind looking into it either, wasnt sure what to work on next anyways</p>



<a name="244358633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244358633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244358633">(Jun 29 2021 at 22:53)</a>:</h4>
<p>but if you wanna you can do it of course</p>



<a name="244358729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244358729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244358729">(Jun 29 2021 at 22:54)</a>:</h4>
<p>I'm not going to fix that immediately, first I want to understand how chalk/hir_ty works a bit better</p>



<a name="244362487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244362487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244362487">(Jun 29 2021 at 23:40)</a>:</h4>
<p>Well took a quick peek at it and pushed the problem from <code>TypeRef</code> to the point where we create the where clauses from <code>TypeBound</code>s which probably wont help too much. As it just drops all hrtb lifetimes there now  but that's as far as my knowledge here goes <a href="https://github.com/rust-analyzer/rust-analyzer/pull/9431">https://github.com/rust-analyzer/rust-analyzer/pull/9431</a></p>



<a name="244385430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244385430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244385430">(Jun 30 2021 at 07:16)</a>:</h4>
<p>hmm I thought we just ignored the <code>for</code> and lowered it as a normal bound :/</p>



<a name="244394195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244394195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244394195">(Jun 30 2021 at 08:55)</a>:</h4>
<p>I think we do that for where clauses? We dont for type bounds yet at least</p>



<a name="244411284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411284">(Jun 30 2021 at 11:58)</a>:</h4>
<p>I don't quite understand the logic here:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">sig_ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TyKind</span>::<span class="n">Function</span><span class="p">(</span><span class="n">FnPointer</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="n">num_binders</span>: <span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">                    </span><span class="n">sig</span>: <span class="nc">FnSig</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">abi</span>: <span class="p">(),</span><span class="w"> </span><span class="n">safety</span>: <span class="nc">chalk_ir</span>::<span class="n">Safety</span>::<span class="n">Safe</span><span class="p">,</span><span class="w"> </span><span class="n">variadic</span>: <span class="nc">false</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w">                    </span><span class="n">substitution</span>: <span class="nc">FnSubst</span><span class="p">(</span><span class="w"></span>
<span class="w">                        </span><span class="n">Substitution</span>::<span class="n">from_iter</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Interner</span><span class="p">,</span><span class="w"> </span><span class="n">sig_tys</span><span class="p">.</span><span class="n">clone</span><span class="p">()).</span><span class="n">shifted_in</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Interner</span><span class="p">),</span><span class="w"></span>
<span class="w">                    </span><span class="p">),</span><span class="w"></span>
<span class="w">                </span><span class="p">})</span><span class="w"></span>
<span class="w">                </span><span class="p">.</span><span class="n">intern</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Interner</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>This always creates an <code>FnPointer</code> that has a fixed 0 higher-ranked regions, but it still calls <code>shifted_in</code>. Wouldn't that shift the indices past the (non-existent) implicit binder in the <code>FnPointer</code>?</p>



<a name="244411343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411343">(Jun 30 2021 at 11:59)</a>:</h4>
<p>de bruijn indices are conceptually simple, but I can't wrap my head around how they work in chalk</p>



<a name="244411549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411549">(Jun 30 2021 at 12:00)</a>:</h4>
<p>chalk (like rustc, I think?) counts binders, not bound variables, so when putting something inside the FnPointer we need to shift in even if the binder has 0 variables</p>



<a name="244411625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411625">(Jun 30 2021 at 12:01)</a>:</h4>
<p>as a general note though, the handling of function binders and higher-ranked bounds in hir_ty is, let's say, not really clean and will probably break in lots of places once we actually have lifetimes</p>



<a name="244411739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411739">(Jun 30 2021 at 12:02)</a>:</h4>
<p>ah, so every <code>Binders</code> instance is counted, not every variable inside</p>



<a name="244411792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411792">(Jun 30 2021 at 12:03)</a>:</h4>
<p>yeah. that's why <code>BoundVar</code> has two indices, the debruijn index for the binder and the index for the variable in that binder</p>



<a name="244411824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411824">(Jun 30 2021 at 12:03)</a>:</h4>
<p>chalks API for dealing with this function signatures also seems a bit suboptimal here</p>



<a name="244411941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411941">(Jun 30 2021 at 12:04)</a>:</h4>
<p>do we have an equivalent to <code>liberate_late_bound_regions</code> in r-a? presumably no?</p>



<a name="244411947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411947">(Jun 30 2021 at 12:04)</a>:</h4>
<p>I guess there might be some stuff missing. I think one of the main problems is though that we still have our own <code>CallableSig</code> type which doesn't have binders</p>



<a name="244411966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411966">(Jun 30 2021 at 12:04)</a>:</h4>
<p>no <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="244411967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244411967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244411967">(Jun 30 2021 at 12:04)</a>:</h4>
<p>yeah exactly</p>



<a name="244412021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412021">(Jun 30 2021 at 12:05)</a>:</h4>
<p>mostly I find <code>FnPointer</code> unintuitive to construct, and <code>Binder&lt;InternedSlice&gt;</code> is also hard to work with</p>



<a name="244412055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412055">(Jun 30 2021 at 12:05)</a>:</h4>
<p>I'd expect an <code>IntoIterator</code> impl for that that yields <code>Binder&lt;&amp;SliceElement&gt;</code> or something</p>



<a name="244412391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412391">(Jun 30 2021 at 12:08)</a>:</h4>
<p>hm, there is an <code>IntoIterator</code> impl for IntoIterator inside Binders. Seems like one for <code>Binder&lt;InternedSlice&gt;</code> would make sense, but may run into coherence problems... although probably it could be generated by the <code>interned_slice!</code> macros</p>



<a name="244412415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412415">(Jun 30 2021 at 12:08)</a>:</h4>
<p>ah, yeah, that'd work too</p>



<a name="244412465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412465">(Jun 30 2021 at 12:09)</a>:</h4>
<p>although you could also do <code>binder.map(|x| x.iter(&amp;Interner)).into_iter()</code> I guess?</p>



<a name="244412612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412612">(Jun 30 2021 at 12:10)</a>:</h4>
<p>oh, it couldn't be a proper <code>IntoIterator</code> impl anyway since it needs the interner</p>



<a name="244412634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412634">(Jun 30 2021 at 12:10)</a>:</h4>
<p>there could be an inherent method for this though I guess</p>



<a name="244412856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412856">(Jun 30 2021 at 12:12)</a>:</h4>
<p>this works but r-a isn't too happy about it</p>
<p><a href="/user_uploads/4715/aKQQS4rZB39zd0k_MOO5RY39/screenshot-2021-06-30-141210.png">screenshot-2021-06-30-141210.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/aKQQS4rZB39zd0k_MOO5RY39/screenshot-2021-06-30-141210.png" title="screenshot-2021-06-30-141210.png"><img src="/user_uploads/4715/aKQQS4rZB39zd0k_MOO5RY39/screenshot-2021-06-30-141210.png"></a></div>



<a name="244412973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244412973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244412973">(Jun 30 2021 at 12:13)</a>:</h4>
<p>that might be the thing where it fails to project <code>HasInterner::Interner</code> at some points... it's also on <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8961">https://github.com/rust-analyzer/rust-analyzer/issues/8961</a></p>



<a name="244413193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244413193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244413193">(Jun 30 2021 at 12:15)</a>:</h4>
<p>ooh new github issues UI btw</p>



<a name="244413564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244413564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244413564">(Jun 30 2021 at 12:18)</a>:</h4>
<p>is <code>liberate_late_bound_regions</code> just basically a <code>substitute</code> with some different lifetimes? :/</p>



<a name="244413712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244413712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244413712">(Jun 30 2021 at 12:19)</a>:</h4>
<p>I was under the impression I needed that to unify types behind a binder</p>



<a name="244413725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244413725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244413725">(Jun 30 2021 at 12:19)</a>:</h4>
<p>but looks like no</p>



<a name="244413899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244413899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244413899">(Jun 30 2021 at 12:21)</a>:</h4>
<p>well, that sounds kind of like what Chalk does to unify binders</p>



<a name="244419427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244419427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244419427">(Jun 30 2021 at 13:02)</a>:</h4>
<p>I think that was the missing key piece - we can just create an <code>FnPointer</code> type for the expected signature and unify the closure's sig_ty with that</p>



<a name="244419480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20does%20this%20work%3F/near/244419480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20does.20this.20work.3F.html#244419480">(Jun 30 2021 at 13:03)</a>:</h4>
<p>that should handle arbitrary binders correctly</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>